<template>
	<view>
		<view class="box-class bgfff gui-flex gui-align-items-center">
			<view class="item gui-flex gui-flex1" @tap="$u.to(`/pages/index/policy/index`)">
				<image src="../../static/index/class3.png" mode="widthFix" style="height: auto;"></image>
				<view class="right gui-flex gui-column">
					<text class="title c333 gui-bold">政策解读</text>
					<text class="desc f24">及时获取最新资源</text>
				</view>
			</view>
			<view class="item gui-flex gui-flex1" @tap="$u.to(`/pages/mine/company-collect-detail`)">
				<image src="../../static/index/class4.png" mode="widthFix" style="height: auto;"></image>
				<view class="right gui-flex gui-column">
					<text class="title c333 gui-bold">公司信息</text>
					<text class="desc f24">数据更了解</text>
				</view>
			</view>
		</view>
		<view class="list bgfff">
			<view class="flex-ac-jb">
				<view class="title-line gui-bold">人才推荐</view>
				<image class="reflesh-icon" :class="{'reflesh-icon-true':isReflesh}" @tap="refleshList"
					src="../../static/index/reflesh.png" mode="widthFix"></image>
			</view>
			<view class="deliver-list bgfff" style="padding: 0;">
				<view class="deliver-item gui-flex gui-align-items-start" v-for="(item,index) in dataList"
					:key="item.id">
					<view class="photo">
						<gui-image :width="115" :height="115" :src="item.userImg" borderRadius="60rpx" mode="aspectFill"></gui-image>
						<image class="sex_img" v-if="item.userSex == '0'" src="../../static/image/man.png" mode="widthFix"></image>
						<image class="sex_img" v-if="item.userSex == '1'" src="../../static/image/woman.png" mode="widthFix"></image>
					</view>
					<view class="info">
						<view class="f26 c333">
							{{item.userName}}
						</view>
						<view class="f22 stress mt10" v-if="item.comUserCompanyList.length > 0">
							期望地点：{{item.comUserCompanyList[0].postName}}
						</view>
						<view class="f22 c666 mt10" v-if="item.comUserJobHuntList.length > 0">
							期望职位：{{item.comUserJobHuntList[0].addressName}}
						</view>
						<view class="sgin gui-flex">
							<view class="sgin-item" v-if="item.userAge">
								{{item.userAge}}岁
							</view>
							<view class="sgin-item" v-if="item.workTime">
								{{item.workTime}}
							</view>
							<view class="sgin-item" v-if="item.education">
								{{item.education}}
							</view>
							<view class="sgin-item stress-warp" v-if="item.workStatus">
								{{item.workStatus}}
							</view>
						</view>
						<view class="btn_pos">
							<button class="show_btn f20 cfff" @click="$u.to(`/pages/mine/curriculumVitae/curriculum-vitae?type=firm&id=${item.id}`)">查看</button>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		inject,
		defineEmits
	} from 'vue'
	const $u = reactive(inject('$u'))
	const emit = defineEmits(['pageChange'])
	import {
		selectAllUserFollowList
	} from '@/api/company.js';
	const dataList = ref([])
	const isReflesh = ref(false)
	const query = ref({
		pageNum: 1,
		pageSize: 10
	})

	// 人才列表
	const loadRc = (isReload) => {
		let queryParam = Object.assign(query.value, {})
		selectAllUserFollowList(queryParam).then(res => {
			if (res.code == 200) {
				var resultArr = res.rows;
				let total = Math.ceil(res.total / queryParam.pageSize);
				if (queryParam.pageNum >= 2) {
					dataList.value = dataList.value.concat(resultArr);
					emit('pageChange', {
						value: 'stoploadmore'
					})
					// 假定第3页加载了全部数据，通知组件不再加载更多
					// 实际开发由接口返回值来决定
					if (queryParam.pageNum >= total) {
						emit('pageChange', {
							value: 'nomore'
						})
					}
				}
				// 第一页 有可能是第一次加载或者刷新
				else {
					dataList.value = [];
					dataList.value = resultArr;
					// 刷新
					if (isReload) {
						emit('pageChange', {
							value: 'endReload'
						})
					} else {
						emit('pageChange', {
							value: 'stoploadmore'
						})
					}
				}
				query.value.pageNum++;
			}
		})
	}
	loadRc();
	const reload = () => {
		query.value.pageNum = 1;
		loadRc(true);
	}
	const refleshList = ()=> {
		query.value.pageNum = 1;
		let queryParam = Object.assign(query.value, {})
		isReflesh.value = true;
		selectAllUserFollowList(queryParam).then(res => {
			if (res.code == 200) {
				var resultArr = res.rows;
				dataList.value = [];
				dataList.value = resultArr;
				query.value.pageNum++;
				emit('pageChange', {
					value: 'stoploadmore'
				})
			}
		}).finally(() => {
			isReflesh.value = false;
		})
	}
	// 抛出函数
	defineExpose({
		loadRc,
		reload
	})
</script>
<style scoped>
.sgin-item {
    max-width: 120rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
    padding: 0 15rpx;
    box-sizing: border-box;
}
</style>